
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>H2内嵌数据的使用 · JAVA学习积累</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tianwyam">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="cache.html" />
    
    
    <link rel="prev" href="sql_mysql_green_install.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blog.csdn.net/mybook201314" target="_blank" class="custom-link">博客Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">【前言】</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍ABOUT
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第一章】Java基础</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java/java.html">
            
                <a href="../java/java.html">
            
                    
                    计算机基础-操作系统-进程-计算机网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java/java_thread_pool.html">
            
                <a href="../java/java_thread_pool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java/java_ftp.html">
            
                <a href="../java/java_ftp.html">
            
                    
                    FTP文件服务器上传下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java/collection.html">
            
                <a href="../java/collection.html">
            
                    
                    集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../java/collection/java_collection_map.html">
            
                <a href="../java/collection/java_collection_map.html">
            
                    
                    Map&HashMap&HashTable&ConcurrentHashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../java/java_queue.html">
            
                <a href="../java/java_queue.html">
            
                    
                    队列-queue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../java/java_tree.html">
            
                <a href="../java/java_tree.html">
            
                    
                    二叉树遍历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java/java_io_nio.html">
            
                <a href="../java/java_io_nio.html">
            
                    
                    java输入输出流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java/java_exception.html">
            
                <a href="../java/java_exception.html">
            
                    
                    异常exception
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java/java_serialize.html">
            
                <a href="../java/java_serialize.html">
            
                    
                    Java序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java/Java_annotation.html">
            
                <a href="../java/Java_annotation.html">
            
                    
                    注解
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../java/multi.html">
            
                <a href="../java/multi.html">
            
                    
                    多线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                <a href="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                    
                    volatile&synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                <a href="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                    
                    object/wait/notify
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../java/multithread/java_multi_thread_thread.html">
            
                <a href="../java/multithread/java_multi_thread_thread.html">
            
                    
                    thread
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../java/multithread/java_multi_thread_threadpool.html">
            
                <a href="../java/multithread/java_multi_thread_threadpool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../java/multithread/java_multi_thread_lock.html">
            
                <a href="../java/multithread/java_multi_thread_lock.html">
            
                    
                    lock&ReentrantLock&ReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../java/multithread/java_multi_thread_lock_condition.html">
            
                <a href="../java/multithread/java_multi_thread_lock_condition.html">
            
                    
                    lock&condition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../java/multithread/java_multi_thread_tools.html">
            
                <a href="../java/multithread/java_multi_thread_tools.html">
            
                    
                    Java并发工具- CountDownLatch&CyclicBarrier 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../java/multithread/java_multi_thread_tools2.html">
            
                <a href="../java/multithread/java_multi_thread_tools2.html">
            
                    
                    Java同步工具类- CountDownLatch&CyclicBarrier&Semaphore  
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java/java_jvm.html">
            
                <a href="../java/java_jvm.html">
            
                    
                    java虚拟机-JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../java/java_java7new.html">
            
                <a href="../java/java_java7new.html">
            
                    
                    java7新知识- Switch&TWR&Objects 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../java/java_stream.html">
            
                <a href="../java/java_stream.html">
            
                    
                    Java8对集合流操作stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../java/java_stream_groupby.html">
            
                <a href="../java/java_stream_groupby.html">
            
                    
                    java8新语法-Stream-分组groupingBy操作 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../java/java_optional.html">
            
                <a href="../java/java_optional.html">
            
                    
                    java8新语法-Optional 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../java/java_8new_date_api.html">
            
                <a href="../java/java_8new_date_api.html">
            
                    
                    java8-新的日期时间API 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../xml/xml_translation.html">
            
                <a href="../xml/xml_translation.html">
            
                    
                    XML中特殊符号的转译 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../datastructure/binary_complement.html">
            
                <a href="../datastructure/binary_complement.html">
            
                    
                    原码、反码、补码 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../java/basic/javabean2map.html">
            
                <a href="../java/basic/javabean2map.html">
            
                    
                    Java bean转Map 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第二章】算法积累题</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../algorithm/merge_sorted_array.html">
            
                <a href="../algorithm/merge_sorted_array.html">
            
                    
                    算法题 - 合并排序数组 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../algorithm/lowest_score.html">
            
                <a href="../algorithm/lowest_score.html">
            
                    
                    算法题 - 最低分数线问题 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../algorithm/array_sub_list.html">
            
                <a href="../algorithm/array_sub_list.html">
            
                    
                    算法题 - 求数组的子集合 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第三章】框架</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../Spring/springboot.html">
            
                <a href="../Spring/springboot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../Spring/spring_security.html">
            
                <a href="../Spring/spring_security.html">
            
                    
                    SpringSecurity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../linux/linux_commands_springboot_startup.html">
            
                <a href="../linux/linux_commands_springboot_startup.html">
            
                    
                    SpringBoot项目启动脚本
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="10.1" data-path="../Spring/spring/spring_interview_questions_68.html">
            
                <a href="../Spring/spring/spring_interview_questions_68.html">
            
                    
                    Spring面试题68
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="11.1" data-path="../Spring/springboot_auto_config.html">
            
                <a href="../Spring/springboot_auto_config.html">
            
                    
                    SpringBoot自动装载机制 - 源码分析
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="../Spring/spring_feign.html">
            
                <a href="../Spring/spring_feign.html">
            
                    
                    Feign在spring、springboot下使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="13.1" data-path="../Spring/spring_freemarker.html">
            
                <a href="../Spring/spring_freemarker.html">
            
                    
                    Spring boot集成freemarker，生成word文件
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="14.1" data-path="../Spring/spring_freemarker_generate.html">
            
                <a href="../Spring/spring_freemarker_generate.html">
            
                    
                    Freemarker自动生成Java bean代码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="15.1" data-path="../mybatis/mybatis_metadata.html">
            
                <a href="../mybatis/mybatis_metadata.html">
            
                    
                    mybatis中操作元数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.2" data-path="../mybatis/mybatis_batch_exec_sql.html">
            
                <a href="../mybatis/mybatis_batch_exec_sql.html">
            
                    
                    mybatis中insert/update/delete标签中执行多条SQL语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.3" data-path="../mybatis/mybatis_plus.html">
            
                <a href="../mybatis/mybatis_plus.html">
            
                    
                    springboot集成mybatis-plus框架
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="16.1" data-path="../distributed/sharding-jdbc.html">
            
                <a href="../distributed/sharding-jdbc.html">
            
                    
                    【分布式】sharding-jdbc实现分库分表
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第四章】数据库</li>
        
        
    
        <li class="chapter " data-level="17.1" data-path="sql.html">
            
                <a href="sql.html">
            
                    
                    SQL常用使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="18.1" data-path="../redis/redis_study_notes.html">
            
                <a href="../redis/redis_study_notes.html">
            
                    
                    redis学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="18.2" data-path="../redis/redis_list_second_kill.html">
            
                <a href="../redis/redis_list_second_kill.html">
            
                    
                    Redis中的队列list实现秒杀活动抢购
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="19.1" data-path="sql_mysql_green_install.html">
            
                <a href="sql_mysql_green_install.html">
            
                    
                    mysql绿色版安装服务教程
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="19.2" data-path="sql_h2.html">
            
                <a href="sql_h2.html">
            
                    
                    H2内嵌数据的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.3" data-path="cache.html">
            
                <a href="cache.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.4" data-path="mysql/mysql_back_rollback.html">
            
                <a href="mysql/mysql_back_rollback.html">
            
                    
                    MySQL单表备份还原
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第五章】Web</li>
        
        
    
        <li class="chapter " data-level="20.1" data-path="../web/web_js_jquery.html">
            
                <a href="../web/web_js_jquery.html">
            
                    
                    web简单积累
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第六章】Linux</li>
        
        
    
        <li class="chapter " data-level="21.1" data-path="../linux/linux_common_commands.html">
            
                <a href="../linux/linux_common_commands.html">
            
                    
                    linux常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第七章】Windows</li>
        
        
    
        <li class="chapter " data-level="22.1" data-path="../windows/windows_common_commands.html">
            
                <a href="../windows/windows_common_commands.html">
            
                    
                    windows常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第八章】错误集</li>
        
        
    
        <li class="chapter " data-level="23.1" data-path="../error/maven_not_found_local_jar.html">
            
                <a href="../error/maven_not_found_local_jar.html">
            
                    
                    maven引入依赖时识别不到本地仓库的jar
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="24.1" data-path="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                <a href="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                    
                    spring security 配置发生错误 Can't configure antMatchers after anyRequest
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="25.1" data-path="../error/AOP_stream_close_error.html">
            
                <a href="../error/AOP_stream_close_error.html">
            
                    
                    AOP内获取了对请求流操作后报流已经关闭错误的问题
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="26.1" data-path="../tools/github/github_ssh.html">
            
                <a href="../tools/github/github_ssh.html">
            
                    
                    Github ssh key 解决提交后push频繁输入用户名和密码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="27.1" data-path="../error/sharding-jdbc-error-datasources.html">
            
                <a href="../error/sharding-jdbc-error-datasources.html">
            
                    
                    sharding-jdbc-4.1.1版本启动数据源报错问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >H2内嵌数据的使用</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#h2&#x5185;&#x5D4C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4F7F;&#x7528;"><b></b>H2&#x5185;&#x5D4C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4F7F;&#x7528;</a></li><ul><li><span class="title-icon "></span><a href="#&#x8FD0;&#x884C;&#x65B9;&#x5F0F;"><b></b>&#x8FD0;&#x884C;&#x65B9;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#jdbc-url"><b></b>JDBC URL</a></li></ul><li><span class="title-icon "></span><a href="#java&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><b></b>Java&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;</a></li><ul><li><span class="title-icon "></span><a href="#&#x64CD;&#x4F5C;&#x5B9E;&#x4F8B;"><b></b>&#x64CD;&#x4F5C;&#x5B9E;&#x4F8B;</a></li></ul><li><span class="title-icon "></span><a href="#java-web-&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><b></b>Java web &#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;</a></li><ul><li><span class="title-icon "></span><a href="#h2&#x670D;&#x52A1;&#x7684;&#x542F;&#x52A8;"><b></b>H2&#x670D;&#x52A1;&#x7684;&#x542F;&#x52A8;</a></li><li><span class="title-icon "></span><a href="#&#x6570;&#x636E;&#x5E93;&#x521D;&#x59CB;&#x5316;"><b></b>&#x6570;&#x636E;&#x5E93;&#x521D;&#x59CB;&#x5316;</a></li></ul></ul></ul></div><h2 id="h2&#x5185;&#x5D4C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4F7F;&#x7528;"><a name="h2&#x5185;&#x5D4C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#h2&#x5185;&#x5D4C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>H2&#x5185;&#x5D4C;&#x6570;&#x636E;&#x5E93;&#x7684;&#x4F7F;&#x7528;</h2>
<p>&#x200B;    <strong>H2</strong>&#x662F;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x7684;&#x5D4C;&#x5165;&#x5F0F;&#x6570;&#x636E;&#x5E93;&#x5F15;&#x64CE;&#xFF0C;&#x91C7;&#x7528;java&#x8BED;&#x8A00;&#x7F16;&#x5199;&#xFF0C;&#x4E0D;&#x53D7;&#x5E73;&#x53F0;&#x7684;&#x9650;&#x5236;&#x3002;</p>
<p>&#x200B;    &#x540C;&#x65F6;H2&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x5341;&#x5206;&#x65B9;&#x4FBF;&#x7684;web&#x63A7;&#x5236;&#x53F0;&#x7528;&#x4E8E;&#x64CD;&#x4F5C;&#x548C;&#x7BA1;&#x7406;&#x6570;&#x636E;&#x5E93;&#x5185;&#x5BB9;&#x3002;</p>
<p>&#x200B;    H2&#x8FD8;&#x63D0;&#x4F9B;&#x517C;&#x5BB9;&#x6A21;&#x5F0F;&#xFF0C;&#x53EF;&#x4EE5;&#x517C;&#x5BB9;&#x4E00;&#x4E9B;&#x4E3B;&#x6D41;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x56E0;&#x6B64;&#x91C7;&#x7528;H2&#x4F5C;&#x4E3A;&#x5F00;&#x53D1;&#x671F;&#x7684;&#x6570;&#x636E;&#x5E93;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002; </p>
<p>&#x200B;    H2&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x5D4C;&#x5165;&#x578B;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5B83;&#x6700;&#x5927;&#x7684;&#x597D;&#x5904;&#x5C31;&#x662F;&#x53EF;&#x4EE5;&#x5D4C;&#x5165;&#x5230;&#x6211;&#x4EEC;&#x7684;Web&#x5E94;&#x7528;&#x4E2D;&#xFF0C;&#x548C;&#x6211;&#x4EEC;&#x7684;Web&#x5E94;&#x7528;&#x7ED1;&#x5B9A;&#x5728;&#x4E00;&#x8D77;&#xFF0C;&#x6210;&#x4E3A;&#x6211;&#x4EEC;Web&#x5E94;&#x7528;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;</p>
<h3 id="&#x8FD0;&#x884C;&#x65B9;&#x5F0F;"><a name="&#x8FD0;&#x884C;&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x8FD0;&#x884C;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x8FD0;&#x884C;&#x65B9;&#x5F0F;</h3>
<p>H2&#x6570;&#x636E;&#x5E93;&#x6709;&#x4E09;&#x79CD;&#x8FD0;&#x884C;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;&#xFF1A;</p>
<ol>
<li>&#x5D4C;&#x5165;&#x5F0F;(embedded)&#xFF1A;&#x53EF;&#x4EE5;&#x540C;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6253;&#x5305;&#x5728;&#x4E00;&#x8D77;&#x53D1;&#x5E03;&#xFF0C;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x5730;&#x5B58;&#x50A8;&#x5C11;&#x91CF;&#x7ED3;&#x6784;&#x5316;&#x6570;&#x636E;</li>
<li>&#x670D;&#x52A1;&#x6A21;&#x5F0F;&#xFF1A;
 1.TCP/IP server&#xFF1A;&#x652F;&#x6301;&#x5BA2;&#x6237;&#x7AEF;/&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x7684;&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;
 2.web server&#xFF1A;&#x6B64;&#x79CD;&#x8FD0;&#x884C;&#x65B9;&#x5F0F;&#x652F;&#x6301;&#x4F7F;&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x8BBF;&#x95EE;H2 Console
 3.PG server&#xFF1A;&#x652F;&#x6301;PostgreSQL&#x5BA2;&#x6237;&#x7AEF;</li>
<li>&#x5185;&#x5B58;&#x65B9;&#x5F0F;&#xFF1A;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x7F13;&#x5B58;&#xFF0C;&#x4F5C;&#x4E3A;NoSQL&#x7684;&#x4E00;&#x4E2A;&#x8865;&#x5145;&#x3002;
&#x5F53;&#x67D0;&#x4E9B;&#x573A;&#x666F;&#x4E0B;&#x6570;&#x636E;&#x6A21;&#x578B;&#x5FC5;&#x987B;&#x4E3A;&#x5173;&#x7CFB;&#x578B;&#xFF0C;&#x53EF;&#x4EE5;&#x62FF;&#x5B83;&#x5F53;Memcached&#x4F7F;&#xFF0C;&#x4F5C;&#x4E3A;&#x540E;&#x7AEF;MySQL/Oracle&#x7684;&#x4E00;&#x4E2A;&#x7F13;&#x51B2;&#x5C42;&#xFF0C;&#x7F13;&#x5B58;&#x4E00;&#x4E9B;&#x4E0D;&#x7ECF;&#x5E38;&#x53D8;&#x5316;&#x4F46;&#x9700;&#x8981;&#x9891;&#x7E41;&#x8BBF;&#x95EE;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x6BD4;&#x5982;&#x5B57;&#x5178;&#x8868;&#x3001;&#x6743;&#x9650;&#x8868;&#x3002;</li>
</ol>
<h3 id="jdbc-url"><a name="jdbc-url" class="anchor-navigation-ex-anchor" href="#jdbc-url"><i class="fa fa-link" aria-hidden="true"></i></a>JDBC URL</h3>
<p>1&#x3001;&#x5185;&#x5D4C;&#x6A21;&#x5F0F;&#x4E0D;&#x7528;&#x542F;&#x52A8;&#x670D;&#x52A1;&#xFF0C;&#x5DF2;&#x5185;&#x5D4C;&#xFF0C;&#x4E0D;&#x7528;&#x663E;&#x793A;&#x542F;&#x52A8;&#x670D;&#x52A1;</p>
<pre><code class="lang-java">String jdbcURL = <span class="hljs-string">&quot;jdbc:h2:~/h2/db&quot;</span>;
</code></pre>
<p>2&#x3001;TCP/IP server &#x670D;&#x52A1;&#x5668;&#x6A21;&#x5F0F;&#xFF0C;&#x5FC5;&#x987B;&#x8981;&#x663E;&#x793A;&#x542F;&#x52A8;&#x670D;&#x52A1;</p>
<pre><code class="lang-java">String jdbcURL = <span class="hljs-string">&quot;jdbc:h2:tcp://localhost/~/h2/db&quot;</span>;
</code></pre>
<p>3&#x3001;&#x5185;&#x5B58;&#x6A21;&#x5F0F; </p>
<pre><code class="lang-java">String jdbcURL = <span class="hljs-string">&quot;jdbc:h2:mem:h2db&quot;</span>;

<span class="hljs-comment">// &#x6216;&#x8005;</span>

String jdbcURL = <span class="hljs-string">&quot;jdbc:h2:tcp://localhost/mem:h2db&quot;</span>;
</code></pre>
<hr>
<h2 id="java&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><a name="java&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#java&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>Java&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;</h2>
<h3 id="&#x64CD;&#x4F5C;&#x5B9E;&#x4F8B;"><a name="&#x64CD;&#x4F5C;&#x5B9E;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#&#x64CD;&#x4F5C;&#x5B9E;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x64CD;&#x4F5C;&#x5B9E;&#x4F8B;</h3>
<p>H2&#x6570;&#x636E;&#x5E93;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-comment">// ~ &#x7528;&#x6237;&#x76EE;&#x5F55;C:\Users\&#x7528;&#x6237;&#x540D;\</span>
String jdbcURL = <span class="hljs-string">&quot;&#x4E0D;&#x540C;&#x6A21;&#x5F0F;&#x4E0B;&#xFF0C;&#x4E0D;&#x540C;&#x7684;jdbcURL&#xFF0C;&#x5176;&#x4ED6;&#x64CD;&#x4F5C;&#x4E00;&#x6837;&quot;</span>;

<span class="hljs-comment">//&#x8FDE;&#x63A5;&#x6570;&#x636E;&#x5E93;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x7528;&#x6237;&#x540D;</span>
<span class="hljs-keyword">final</span> String user = <span class="hljs-string">&quot;tianya&quot;</span>;

<span class="hljs-comment">//&#x8FDE;&#x63A5;&#x6570;&#x636E;&#x5E93;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x5BC6;&#x7801;</span>
String password = <span class="hljs-string">&quot;123456&quot;</span>;

<span class="hljs-comment">//&#x8FDE;&#x63A5;H2&#x6570;&#x636E;&#x5E93;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x9A71;&#x52A8;&#x7C7B;</span>
<span class="hljs-comment">//org.h2.Driver </span>
String driverClass=<span class="hljs-string">&quot;org.h2.Driver&quot;</span>;

<span class="hljs-keyword">try</span> {

    <span class="hljs-comment">// 1&#x3001;&#x52A0;&#x8F7D;&#x9A71;&#x52A8;</span>
    Class.forName(driverClass);

    <span class="hljs-comment">// 2&#x3001;&#x83B7;&#x53D6;&#x8FDE;&#x63A5;</span>
    Connection connection = DriverManager.getConnection(jdbcURL, user, password);
    Statement statement = connection.createStatement();

    <span class="hljs-comment">// 3&#x3001;&#x6267;&#x884C;&#x64CD;&#x4F5C;</span>
    <span class="hljs-comment">// 3.1&#x3001;&#x5148;&#x5220;&#x9664;&#x8868;&#xFF0C;&#x82E5;&#x5B58;&#x5728;</span>
    statement.execute(<span class="hljs-string">&quot;drop table user_info if exists &quot;</span>);

    <span class="hljs-comment">// 3.2&#x3001;&#x521B;&#x5EFA;&#x8868;</span>
    statement.execute(<span class="hljs-string">&quot;create table user_info(id int primary key, name varchar(10), age int , sex varchar(2) )&quot;</span>);

    <span class="hljs-comment">// 4&#x3001;&#x65B0;&#x589E;</span>
    statement.executeUpdate(<span class="hljs-string">&quot;insert into user_info(id,name,age,sex) values(1,&apos;&#x5F20;&#x4E09;&apos;,23,&apos;&#x7537;&apos; )&quot;</span>);
    statement.executeUpdate(<span class="hljs-string">&quot;insert into user_info(id,name,age,sex) values(2,&apos;&#x674E;&#x56DB;&apos;,25,&apos;&#x7537;&apos; )&quot;</span>);
    statement.executeUpdate(<span class="hljs-string">&quot;insert into user_info(id,name,age,sex) values(3,&apos;&#x738B;&#x4E94;&apos;,33,&apos;&#x7537;&apos; )&quot;</span>);
    statement.executeUpdate(<span class="hljs-string">&quot;insert into user_info(id,name,age,sex) values(4,&apos;&#x73E0;&#x5E18;&apos;,23,&apos;&#x5973;&apos; )&quot;</span>);
    statement.executeUpdate(<span class="hljs-string">&quot;insert into user_info(id,name,age,sex) values(5,&apos;&#x9CA4;&#x9C7C;&apos;,20,&apos;&#x5973;&apos; )&quot;</span>);

    <span class="hljs-comment">// 5&#x3001;&#x67E5;&#x8BE2;</span>
    ResultSet rs = statement.executeQuery(<span class="hljs-string">&quot;select * from user_info&quot;</span>);
    <span class="hljs-keyword">while</span> (rs.next()) {
        System.out.println(rs.getInt(<span class="hljs-number">1</span>) + <span class="hljs-string">&quot; - &quot;</span> + rs.getString(<span class="hljs-number">2</span>) 
        + <span class="hljs-string">&quot; - &quot;</span> + rs.getInt(<span class="hljs-number">3</span>)+ <span class="hljs-string">&quot; - &quot;</span> + rs.getString(<span class="hljs-number">4</span>) );
    }

    <span class="hljs-comment">// &#x91CA;&#x653E;&#x8D44;&#x6E90;</span>
    statement.close();
    connection.close();

} <span class="hljs-keyword">catch</span> (Exception e) {
    e.printStackTrace();
}
</code></pre>
<hr>
<h2 id="java-web-&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><a name="java-web-&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#java-web-&#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>Java web &#x5E94;&#x7528;&#x4E2D;&#x7684;&#x4F7F;&#x7528;</h2>
<h3 id="h2&#x670D;&#x52A1;&#x7684;&#x542F;&#x52A8;"><a name="h2&#x670D;&#x52A1;&#x7684;&#x542F;&#x52A8;" class="anchor-navigation-ex-anchor" href="#h2&#x670D;&#x52A1;&#x7684;&#x542F;&#x52A8;"><i class="fa fa-link" aria-hidden="true"></i></a>H2&#x670D;&#x52A1;&#x7684;&#x542F;&#x52A8;</h3>
<h4 id="1&#x547D;&#x4EE4;&#x884C;&#x542F;&#x52A8;&#x670D;&#x52A1;"><a name="1&#x547D;&#x4EE4;&#x884C;&#x542F;&#x52A8;&#x670D;&#x52A1;" class="anchor-navigation-ex-anchor" href="#1&#x547D;&#x4EE4;&#x884C;&#x542F;&#x52A8;&#x670D;&#x52A1;"><i class="fa fa-link" aria-hidden="true"></i></a>1.&#x547D;&#x4EE4;&#x884C;&#x542F;&#x52A8;&#x670D;&#x52A1;</h4>
<pre><code class="lang-bash">java -cp h2*.jar org.h2.tools.Server -?

&#x5E38;&#x89C1;&#x7684;&#x9009;&#x9879;&#x5982;&#x4E0B;&#xFF1A;

-web&#xFF1A;&#x542F;&#x52A8;&#x652F;&#x6301;H2 Console&#x7684;&#x670D;&#x52A1;
-webPort &lt;port&gt;&#xFF1A;&#x670D;&#x52A1;&#x542F;&#x52A8;&#x7AEF;&#x53E3;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;8082
-browser&#xFF1A;&#x542F;&#x52A8;H2 Console web&#x7BA1;&#x7406;&#x9875;&#x9762;
-tcp&#xFF1A;&#x4F7F;&#x7528;TCP server&#x6A21;&#x5F0F;&#x542F;&#x52A8;
-pg&#xFF1A;&#x4F7F;&#x7528;PG server&#x6A21;&#x5F0F;&#x542F;&#x52A8;
</code></pre>
<p>&#x5982;&#xFF1A;</p>
<pre><code class="lang-bash"><span class="hljs-comment">## &#x6D4F;&#x89C8;&#x5668;web&#x670D;&#x52A1;&#x65B9;&#x5F0F;</span>
java -jar h2*.jar org.h2.tools.Server -web -webPort 8082 -browser 

<span class="hljs-comment">## TCP&#x670D;&#x52A1;&#x65B9;&#x5F0F;</span>
java -jar h2*.jar org.h2.tools.Server -tcp -tcpPort 9092 -tcpSSL
</code></pre>
<h4 id="2servlet&#x7684;&#x65B9;&#x5F0F;"><a name="2servlet&#x7684;&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#2servlet&#x7684;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.Servlet&#x7684;&#x65B9;&#x5F0F;</h4>
<p>&#x6CE8;&#x89E3;&#x7684;&#x65B9;&#x5F0F;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.tianya.mw.web;

<span class="hljs-keyword">import</span> java.sql.SQLException;
<span class="hljs-keyword">import</span> java.util.HashMap;
<span class="hljs-keyword">import</span> java.util.Map;

<span class="hljs-keyword">import</span> javax.servlet.ServletContext;
<span class="hljs-keyword">import</span> javax.servlet.ServletContextEvent;
<span class="hljs-keyword">import</span> javax.servlet.ServletContextListener;
<span class="hljs-keyword">import</span> javax.servlet.ServletRegistration.Dynamic;
<span class="hljs-keyword">import</span> javax.servlet.annotation.WebListener;

<span class="hljs-keyword">import</span> org.apache.log4j.Logger;
<span class="hljs-keyword">import</span> org.h2.server.web.WebServlet;
<span class="hljs-keyword">import</span> org.h2.tools.Server;

<span class="hljs-comment">/**
 * Copyright: Copyright (c) 2019 tianwyam
 * 
 * <span class="hljs-doctag">@ClassName</span>: H2DBServerListener.java
 * <span class="hljs-doctag">@Description</span>: &#x5728;WEB&#x5E94;&#x7528;&#x4E2D;&#x542F;&#x52A8;H2&#x6570;&#x636E;&#x5E93;&#x670D;&#x52A1;&#x7684;&#x76D1;&#x542C;&#x5668;
 * <span class="hljs-doctag">@version</span>: v1.0.0
 * <span class="hljs-doctag">@author</span>: tianwyam
 * <span class="hljs-doctag">@date</span>: 2019&#x5E74;3&#x6708;18&#x65E5; &#x4E0A;&#x5348;9:56:21
 */</span>
<span class="hljs-meta">@WebListener</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">H2DBServerListener</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ServletContextListener</span> </span>{

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">transient</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger log = Logger.getLogger(H2DBServerListener.class);
    <span class="hljs-comment">// H2 DB &#x670D;&#x52A1;</span>
    <span class="hljs-keyword">private</span> Server server;

    <span class="hljs-comment">// H2 tcp&#x8BBF;&#x95EE;&#x7684;&#x7AEF;&#x53E3;</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> H2_DB_SERVER_PORT = <span class="hljs-number">8082</span> ;

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">contextInitialized</span><span class="hljs-params">(ServletContextEvent event)</span> </span>{


        <span class="hljs-keyword">try</span> {

            <span class="hljs-comment">// &#x542F;&#x52A8;H2&#x6570;&#x636E;&#x5E93;&#x670D;&#x52A1;</span>
            log.info(<span class="hljs-string">&quot;&#x542F;&#x52A8;H2&#x6570;&#x636E;&#x5E93;...&quot;</span>);
            log.info(String.format(<span class="hljs-string">&quot;TCP&#x5BA2;&#x6237;&#x7AEF;&#x8BBF;&#x95EE;&#x7AEF;&#x53E3;&#xFF1A;%s&quot;</span>, H2_DB_SERVER_PORT));
            <span class="hljs-comment">// &#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x4E3A;8082</span>
            server = Server.createTcpServer(
                    <span class="hljs-string">&quot;-tcpPort&quot;</span>, 
                    String.valueOf(H2_DB_SERVER_PORT), 
                    <span class="hljs-string">&quot;-tcpAllowOthers&quot;</span>).start();
            log.info(<span class="hljs-string">&quot;H2&#x6570;&#x636E;&#x5E93;&#x542F;&#x52A8;&#x6210;&#x529F;...&quot;</span>);


            <span class="hljs-comment">// &#x6CE8;&#x89E3;&#x65B9;&#x5F0F; &#x6DFB;&#x52A0; H2 DB console &#x8BBF;&#x95EE; WebServlet</span>
            <span class="hljs-comment">// &#x6CE8;&#x518C; H2&#x6570;&#x636E;&#x5E93; web &#x63A7;&#x5236;&#x53F0;  </span>
            <span class="hljs-comment">// &#x6DFB;&#x52A0; org.h2.server.web.WebServlet</span>
            ServletContext servletContext = event.getServletContext();
            Dynamic webServlet = servletContext.addServlet(<span class="hljs-string">&quot;H2Console&quot;</span>, WebServlet.class);
            <span class="hljs-comment">// &#x63A7;&#x5236;&#x53F0; &#x8BBF;&#x95EE;&#x8DEF;&#x5F84;</span>
            webServlet.addMapping(<span class="hljs-string">&quot;/console/*&quot;</span>);
            webServlet.setLoadOnStartup(<span class="hljs-number">1</span>);
            <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x914D;&#x7F6E;</span>
            Map&lt;String, String&gt; initParameters = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
            initParameters.put(<span class="hljs-string">&quot;allowOthers&quot;</span>, <span class="hljs-string">&quot;true&quot;</span>);
            initParameters.put(<span class="hljs-string">&quot;trace&quot;</span>, <span class="hljs-string">&quot;true&quot;</span>);
            webServlet.setInitParameters(initParameters);

            log.info(<span class="hljs-string">&quot;H2 CONSOLE &#x9ED8;&#x8BA4;&#x8BBF;&#x95EE;URL&#xFF1A;http://localhost:8080/[project_name]/console/&quot;</span>);


        } <span class="hljs-keyword">catch</span> (SQLException e) {
            log.error(<span class="hljs-string">&quot;H2&#x6570;&#x636E;&#x5E93;&#x542F;&#x52A8;&#x5931;&#x8D25;&#xFF01;&quot;</span>, e);
        }

    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">contextDestroyed</span><span class="hljs-params">(ServletContextEvent event)</span> </span>{

        <span class="hljs-comment">// &#x505C;&#x6B62;&#x670D;&#x52A1;</span>
        <span class="hljs-keyword">if</span> (server != <span class="hljs-keyword">null</span>) {
            log.info(<span class="hljs-string">&quot;&#x5173;&#x95ED;H2&#x6570;&#x636E;&#x5E93;...&quot;</span>);
            server.shutdown();
            log.info(<span class="hljs-string">&quot;&#x5173;&#x95ED;H2&#x6570;&#x636E;&#x5E93;&#x6210;&#x529F;...&quot;</span>);
        }
    }

}
</code></pre>
<p>web.xml&#x914D;&#x7F6E;&#x65B9;&#x5F0F;</p>
<pre><code class="lang-xml">
<span class="hljs-comment">&lt;!-- &#x6CE8;&#x518C;&#x670D;&#x52A1;&#x76D1;&#x542C; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">listener</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">listener-class</span>&gt;</span>com.tianya.mw.web.H2DBServerListener<span class="hljs-tag">&lt;/<span class="hljs-name">listener-class</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">listener</span>&gt;</span>

<span class="hljs-comment">&lt;!-- &#x4F7F;&#x7528;H2&#x63A7;&#x5236;&#x53F0;&#x7684;Servlet H2&#x63A7;&#x5236;&#x53F0;&#x662F;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#xFF0C;
&#x5305;&#x62EC;&#x5B83;&#x81EA;&#x5DF1;&#x7684;Web&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4F46;&#x5B83;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;servlet&#x4F5C;&#x4E3A;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">servlet</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>H2Console<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-class</span>&gt;</span>org.h2.server.web.WebServlet<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-class</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">init-param</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>webAllowOthers<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">init-param</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">init-param</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>trace<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">init-param</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">load-on-startup</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">servlet</span>&gt;</span>

<span class="hljs-comment">&lt;!-- &#x6620;&#x5C04;H2&#x63A7;&#x5236;&#x53F0;&#x7684;&#x8BBF;&#x95EE;&#x8DEF;&#x5F84; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>H2Console<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/console/*<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span>
</code></pre>
<p>&#x8BBF;&#x95EE; &#x67E5;&#x770B;&#x662F;&#x5426;&#x670D;&#x52A1;&#x542F;&#x52A8;&#x6210;&#x529F;</p>
<pre><code class="lang-http">http://localhost:8080/[project_name]/console/
</code></pre>
<h4 id="3maven&#x63D2;&#x4EF6;&#x65B9;&#x5F0F;"><a name="3maven&#x63D2;&#x4EF6;&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#3maven&#x63D2;&#x4EF6;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.maven&#x63D2;&#x4EF6;&#x65B9;&#x5F0F;</h4>
<pre><code class="lang-xml">
<span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">finalName</span>&gt;</span>LearnH2DB<span class="hljs-tag">&lt;/<span class="hljs-name">finalName</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- maven&#x63D2;&#x4EF6;&#x65B9;&#x5F0F;&#x542F;&#x52A8; H2 DB &#x670D;&#x52A1; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.codehaus.mojo<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>exec-maven-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">executions</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">execution</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">goals</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">goal</span>&gt;</span>java<span class="hljs-tag">&lt;/<span class="hljs-name">goal</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">goals</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">execution</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">executions</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">mainClass</span>&gt;</span>org.h2.tools.Server<span class="hljs-tag">&lt;/<span class="hljs-name">mainClass</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">arguments</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">argument</span>&gt;</span>-web<span class="hljs-tag">&lt;/<span class="hljs-name">argument</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">argument</span>&gt;</span>-webPort<span class="hljs-tag">&lt;/<span class="hljs-name">argument</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">argument</span>&gt;</span>8082<span class="hljs-tag">&lt;/<span class="hljs-name">argument</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">argument</span>&gt;</span>-browser<span class="hljs-tag">&lt;/<span class="hljs-name">argument</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">arguments</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span>
</code></pre>
<p>&#x6267;&#x884C;&#x547D;&#x4EE4;</p>
<pre><code class="lang-bash">mvn <span class="hljs-built_in">exec</span>:java
</code></pre>
<p>&#x76F8;&#x5F53;&#x4E8E;</p>
<pre><code class="lang-bash">java -jar h2*.jar org.h2.tools.Server -web -webPort 8082 -browser
</code></pre>
<hr>
<h3 id="&#x6570;&#x636E;&#x5E93;&#x521D;&#x59CB;&#x5316;"><a name="&#x6570;&#x636E;&#x5E93;&#x521D;&#x59CB;&#x5316;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x636E;&#x5E93;&#x521D;&#x59CB;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6570;&#x636E;&#x5E93;&#x521D;&#x59CB;&#x5316;</h3>
<h4 id="1maven&#x65B9;&#x5F0F;"><a name="1maven&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#1maven&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.maven&#x65B9;&#x5F0F;</h4>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- &#x521D;&#x59CB;&#x5316; &#x914D;&#x7F6E;  --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">profiles</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">profile</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">id</span>&gt;</span>init-db<span class="hljs-tag">&lt;/<span class="hljs-name">id</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">build</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>maven-antrun-plugin<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.8<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">target</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">file</span>=<span class="hljs-string">&quot;src/main/resources/h2_jdbc.properties&quot;</span> /&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">sql</span> <span class="hljs-attr">driver</span>=<span class="hljs-string">&quot;${jdbc.driver}&quot;</span> 
                                <span class="hljs-attr">url</span>=<span class="hljs-string">&quot;${jdbc.url}&quot;</span> 
                                <span class="hljs-attr">userid</span>=<span class="hljs-string">&quot;${jdbc.username}&quot;</span>
                                <span class="hljs-attr">password</span>=<span class="hljs-string">&quot;${jdbc.password}&quot;</span> 
                                <span class="hljs-attr">onerror</span>=<span class="hljs-string">&quot;continue&quot;</span>
                                <span class="hljs-attr">encoding</span>=<span class="hljs-string">&quot;${project.build.sourceEncoding}&quot;</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">classpath</span> <span class="hljs-attr">refid</span>=<span class="hljs-string">&quot;maven.test.classpath&quot;</span> /&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">transaction</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;src/main/resources/sql/h2/schema.sql&quot;</span> /&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">transaction</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;src/main/resources/sql/h2/data.sql&quot;</span> /&gt;</span>
                            <span class="hljs-tag">&lt;/<span class="hljs-name">sql</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">target</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">build</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">profile</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">profiles</span>&gt;</span>
</code></pre>
<p>&#x6267;&#x884C;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-bash">mvn antrun:run -P init-db
</code></pre>
<h4 id="2spring&#x65B9;&#x5F0F;"><a name="2spring&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#2spring&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.spring&#x65B9;&#x5F0F;</h4>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">profile</span>=<span class="hljs-string">&quot;test&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:property-placeholder</span> <span class="hljs-attr">ignore-resource-not-found</span>=<span class="hljs-string">&quot;true&quot;</span>
        <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;classpath*:/*_jdbc.properties&quot;</span> /&gt;</span>    

    <span class="hljs-comment">&lt;!-- Spring Simple&#x8FDE;&#x63A5;&#x6C60; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.jdbc.datasource.SimpleDriverDataSource&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;driverClass&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.driver}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;url&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.url}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;username&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.username}&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;password&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.password}&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x521D;&#x59CB;&#x5316;&#x6570;&#x636E;&#x8868;&#x7ED3;&#x6784; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">jdbc:initialize-database</span> <span class="hljs-attr">data-source</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ignore-failures</span>=<span class="hljs-string">&quot;ALL&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">jdbc:script</span> <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;classpath:sql/h2/schema.sql&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">jdbc:script</span> <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;classpath:sql/h2/data.sql&quot;</span> <span class="hljs-attr">encoding</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">jdbc:initialize-database</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright @copy tianwyam 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-10-06 14:05:47
</span></footer>
                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="sql_mysql_green_install.html" class="navigation navigation-prev " aria-label="Previous page: mysql绿色版安装服务教程">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="cache.html" class="navigation navigation-next " aria-label="Next page: 缓存">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"H2内嵌数据的使用","level":"19.2","depth":1,"next":{"title":"缓存","level":"19.3","depth":1,"path":"SQL/cache.md","ref":"SQL/cache.md","articles":[]},"previous":{"title":"mysql绿色版安装服务教程","level":"19.1","depth":1,"path":"SQL/sql_mysql_green_install.md","ref":"SQL/sql_mysql_green_install.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","github","tbfed-pagefooter","splitter","pageview-count","anchor-navigation-ex","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright @copy tianwyam 2021","modify_label":"最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"github":{"url":"https://github.com/tianwyam"},"livereload":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"pageview-count":{},"expandable-chapters-small":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tianwyam","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JAVA学习积累","links":{"sidebar":{"博客Blog":"https://blog.csdn.net/mybook201314"}},"gitbook":"*","description":"积累Java学习过程中的知识点，俗话说：好记性不如烂笔头"},"file":{"path":"SQL/sql_h2.md","mtime":"2019-10-06T06:05:47.774Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-03T12:24:01.188Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

